package com.panopset.nls;

import static com.panopset.UtilIO.*;
import static com.panopset.Util.*;

import java.io.File;

import com.panopset.Strings;

/**
 * Translator operates on a National Language System (NLS) properties directory.
 * This directory will contain a properties file for various languages. English,
 * for example, would be stored in <b>en.properties</b>.
 *
 * There are many on-line translators available, which you may use to translate
 * your application or web site content.
 *
 * There are 3 steps to adding languages:
 *
 * <ol>
 * <li>
 * Create a properties file in your native language.</li>
 * <li>
 * Launch Panopset Translator, (available in the Panopset Flywheel jar, and on
 * Panopset.com) which takes your native properties file and puts it in a line
 * separated file which you may use in an on-line translator.</li>
 * <li>
 * Use Panopset Translator to reformat the translated text in to a properties
 * file, which will be in the same directory as your native language properties
 * file.</li>
 * </ol>
 *
 * Translator will recognize which languages are available based on whether or
 * not a properties file exists for each language.
 *
 * Most languages that are easily translatable on the web have a flag icon
 * associated with it already, available from this Translator object. If there
 * is one that you don't have, fortunately Flywheel is open source and you may
 * easily add yours.
 *
 * Once you have created a directory of properties files with this program, this
 * program functions as a utility class that allows you to represent the flags
 * of each language you provided in either your Java application or your web
 * site. Panopset.com provides examples for both of these cases.
 *
 * @author Karl Dinwiddie
 *
 */
public final class Translator {

    /**
     * This constructor is used only for running as a Swing application to
     * manage an NLS properties directory.
     */
    protected Translator() { }

    /**
     *
     * @param propertiesPath Properties path.
     */
    public Translator(final String propertiesPath) {
        this(new File(propertiesPath));
    }

    /**
     *
     * @param propertiesDirectory Properties directory.
     */
    public Translator(final File propertiesDirectory) {
        this();
        setPropertiesDirectory(propertiesDirectory);
    }

    /**
     * Properties directory.
     */
    private File propsDir;

    /**
     * If no directory has been provided in the constructor, the user
     * will be prompted to provide one.
     * @return File representing the directory that contains the NLS properties.
     */
    public File propertiesDirectory() {
        while (propsDir == null) {
            propsDir = getDirectoryFromUser(new File(Strings.USER_HOME),
                    x("Please select a directory"));
        }
        return propsDir;
    }

    /**
     * Set the properties directory.
     * @param propertiesDirectory Properties directory.
     */
    public void setPropertiesDirectory(final File propertiesDirectory) {
        this.propsDir = propertiesDirectory;
    }

}
